package com.vip.jwt.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vip.jwt.common.entity.R;
import com.vip.jwt.entity.LoggerOnline;
import com.vip.jwt.entity.LoggerOperation;
import com.vip.jwt.service.LoggerOnlineService;
import com.vip.jwt.service.LoggerOperationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author vip
 * @since 2021-05-28
 */
@RestController
@RequestMapping("/api/logger/operation")
public class LoggerOperationController {

    @Resource
    private LoggerOperationService loggerOperationService;

    @DeleteMapping("/{id}")
    public Object deleteById(@PathVariable String id){
        loggerOperationService.removeById(id);
        return R.ok();
    }

    @GetMapping("/{page}/{limit}")
    public Object pageLoggerOperation(@PathVariable Long page, @PathVariable Long limit){
        Page<LoggerOperation> loggerOnlinePage = new Page<>(page,limit);
        loggerOnlinePage = loggerOperationService.page(loggerOnlinePage);
        return R.ok().data("data",loggerOnlinePage);
    }

    @GetMapping("/{page}/{limit}/{startDate}/{endDate}")
    public Object pageLoggerOperationByDate(@PathVariable Long page, @PathVariable Long limit
            ,@PathVariable String startDate,@PathVariable String endDate){
        Page<LoggerOperation> loggerOnlinePage = new Page<>(page,limit);
        QueryWrapper<LoggerOperation> loggerOperationQueryWrapper = new QueryWrapper<>();
        loggerOperationQueryWrapper.between("log_time",startDate,endDate);
        loggerOnlinePage = loggerOperationService.page(loggerOnlinePage,loggerOperationQueryWrapper);
        return R.ok().data("data",loggerOnlinePage);
    }

}

